
import { Vue, Component } from 'vue-property-decorator'
import PageContainer from '@/moduleC/components/layout/PageContainer.vue'
import { api } from '@/moduleC/api'
import store from '@/moduleC/store'

interface CollectionItem {
	image: string
	name: string
	businessHours: string
	distance: number
}

interface ComponentData {
	statusBarHeight: number
	navHeight: number
	collectionList: CollectionItem[]
	page: number
	pageSize: number
	hasMore: boolean
	isRefreshing: boolean
	loadingText: string
}

interface Response {
	// 定义响应类型
	[key: string]: any;
}


@Component({
  components: {
    PageContainer
  }
})
export default class FavoritePage extends Vue {
	private statusBarHeight= 0
	private navHeight= 0
	private collectionList: CollectionItem[] = []
	private page= 1
	private pageSize=10
	private hasMore= true
	private isRefreshing=false
	private loadingText='加载中...'
	onLoad() {
		const baseFn = (data : any[]) : CollectionItem[] => {
			const sportlist : CollectionItem[] = [];
			data.forEach((el) => {
				const result : CollectionItem = {
					image: el.img,
					name: el.region,
					businessHours: el.detail.time,
					distance: el.distance
				}
				sportlist.push(result);
			})
			return sportlist
		}
	
		const systemInfo = uni.getSystemInfoSync()
		if (systemInfo.statusBarHeight !== undefined) {
			this.statusBarHeight = systemInfo.statusBarHeight
			this.navHeight = systemInfo.statusBarHeight + 44
		}
	
		const datalist = uni.getStorageSync('_collectionList');
		this.collectionList = baseFn(datalist)
	}
	gotoStore() : void {
		uni.navigateTo({
			url: '/moduleA/recommendation/store/index'
		})
	}
	
	cancel(data : CollectionItem, idx : number) : void {
		const _this = this;
		uni.showModal({
			title: '提示',
			content: '确定取消该收藏？',
			success(res : UniApp.ShowModalSuccessResult) {
				if (res.confirm) {
					_this.collectionList.splice(idx, 1);
					const datalist = uni.getStorageSync('_collectionList');
					datalist.splice(idx, 1);
					uni.setStorageSync('_collectionList', datalist);
				}
			}
		})
	}
	
	goBack() : void {
		uni.navigateBack()
	}
	
	async fetchBillList() : Promise<void> {
		uni.showLoading();
		await new Promise(resolve => setTimeout(resolve, 1000))
		uni.hideLoading();
	}
	
	handleResponse(res : Response) {
		// 处理响应
	}
}